//
/**
 *
 *File name:		LXNavigationController.swift
 *History:		yoctech create on 2021/5/13
 *Description:
 
 */


import UIKit
import LXExtensions

/*
 想要隐藏n某个viewController上的导航栏,直接让它遵循该协议,无需实现方法;
 */
@objc protocol LXNavigationBarHideProtocol {
    
}

class LXNavigationController: UINavigationController {
    
    var popDelegate: UIGestureRecognizerDelegate?
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        
        self.popDelegate = self.interactivePopGestureRecognizer?.delegate
        self.delegate = self
                
        self.navigationBar.lx_hideBackTitle()

    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        view.endEditing(true)
    }
    

}


extension LXNavigationController :UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

        self.setNavigationBarHidden(viewController.conforms(to: LXNavigationBarHideProtocol.self), animated: animated)
    }
    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        viewController.navigationController?.navigationBar.lx_hideBackTitle()
        
        if viewController == self.viewControllers[0] {
            
            self.interactivePopGestureRecognizer!.delegate = self.popDelegate
        }
        else {
            self.interactivePopGestureRecognizer!.delegate = nil
        }

    }
}

